package com.zenithmind.gateway.event;

import java.time.LocalDateTime;

/**
 * 网关事件基类
 * 遵循开闭原则：可以扩展新的事件类型而无需修改现有代码
 */
public abstract class GatewayEvent {
    
    private final String eventId;
    private final LocalDateTime timestamp;
    private final String eventType;
    
    protected GatewayEvent(String eventType) {
        this.eventId = java.util.UUID.randomUUID().toString();
        this.timestamp = LocalDateTime.now();
        this.eventType = eventType;
    }
    
    public String getEventId() {
        return eventId;
    }
    
    public LocalDateTime getTimestamp() {
        return timestamp;
    }
    
    public String getEventType() {
        return eventType;
    }
    
    /**
     * 请求开始事件
     */
    public static class RequestStartEvent extends GatewayEvent {
        private final String requestId;
        private final String path;
        private final String method;
        private final String userId;
        
        public RequestStartEvent(String requestId, String path, String method, String userId) {
            super("REQUEST_START");
            this.requestId = requestId;
            this.path = path;
            this.method = method;
            this.userId = userId;
        }
        
        public String getRequestId() { return requestId; }
        public String getPath() { return path; }
        public String getMethod() { return method; }
        public String getUserId() { return userId; }
    }
    
    /**
     * 请求完成事件
     */
    public static class RequestCompleteEvent extends GatewayEvent {
        private final String requestId;
        private final int statusCode;
        private final long executionTime;
        
        public RequestCompleteEvent(String requestId, int statusCode, long executionTime) {
            super("REQUEST_COMPLETE");
            this.requestId = requestId;
            this.statusCode = statusCode;
            this.executionTime = executionTime;
        }
        
        public String getRequestId() { return requestId; }
        public int getStatusCode() { return statusCode; }
        public long getExecutionTime() { return executionTime; }
    }
    
    /**
     * 请求错误事件
     */
    public static class RequestErrorEvent extends GatewayEvent {
        private final String requestId;
        private final String error;
        private final long executionTime;
        
        public RequestErrorEvent(String requestId, String error, long executionTime) {
            super("REQUEST_ERROR");
            this.requestId = requestId;
            this.error = error;
            this.executionTime = executionTime;
        }
        
        public String getRequestId() { return requestId; }
        public String getError() { return error; }
        public long getExecutionTime() { return executionTime; }
    }
}
